package com.lfg.leetcode.leetcode0;

public class No73setZeroes {

    public static void main(String[] args) {
        int[][] array = new int[3][4];
        array[0] = new int[]{0, 1, 2, 0};
        array[1] = new int[]{3, 4, 5, 2};
        array[2] = new int[]{1, 3, 1, 5};
        setZeroes(array);
        System.out.println("[" + array + "]");
    }


    public static void setZeroes(int[][] matrix) {
        int y = matrix.length;
        int x = matrix[0].length;
        int[][] flag = new int[y][x];
        for (int i = 0; i < y; i++) {
            System.arraycopy(matrix[i], 0, flag[i], 0, x);
        }
        for (int i = 0; i < y; i++) {
            for (int j = 0; j < x; j++) {
                if (flag[i][j] != 0) {
                    continue;
                }
                for (int n = 0; n < y; n++) {
                    matrix[n][j] = 0;
                }
                for (int n = 0; n < x; n++) {
                    matrix[i][n] = 0;
                }
            }
        }
    }

    public static void setZeroes2(int[][] matrix) {
        int y = matrix.length;
        int x = matrix[0].length;
        int[][] flag = new int[y][x];
        for (int i = 0; i < y; i++) {
            System.arraycopy(matrix[i], 0, flag[i], 0, x);
        }
        for (int i = 0; i < y; i++) {
            for (int j = 0; j < x; j++) {
                if (flag[i][j] != 0) {
                    continue;
                }
                for (int n = 0; n < y; n++) {
                    matrix[n][j] = 0;
                }
                for (int n = 0; n < x; n++) {
                    matrix[i][n] = 0;
                }
            }
        }
    }
}

